<template>
  <div class="main">
    <el-row class="warp">
      <!--
Form 组件提供了表单验证的功能，只需要通过 rule 属性传入约定的验证规则，并 Form-Item 的 prop 属性设置为需校验的字段名即可。具体可以参考官网：http://element.eleme.io/#/zh-CN/component/form
-->
      <el-col :span="24" class="warp-main">
        <el-form
          ref="infoForm"
          :model="infoForm"
          label-width="120px"
        >
          <el-form-item label="邮件发送者" >
            <el-input v-model="infoForm.from" ></el-input>
          </el-form-item>
          <el-form-item label="邮件接受者">
               <el-input v-model="infoForm.get"></el-input>
          </el-form-item>
           <el-form-item label="邮件标题">
               <el-input v-model="infoForm.title"></el-input>
          </el-form-item>

          <!--使用编辑器-->
          <el-form-item label="详细">
            <div class="edit_container">
              <quill-editor
                v-model="infoForm.content"
                ref="myQuillEditor"
                class="editer"
                style="height:320px"
                :options="editorOption"
                @ready="onEditorReady($event)"
              >
              </quill-editor>
            </div>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="margin-top: 80px" @click="onSubmit"
              >确认提交</el-button
            >
            <el-button type="primary" style="margin-top: 80px" @click="history"
              >历史记录</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { quillEditor } from "vue-quill-editor"; //调用编辑器
import {sendMial} from "@/api/chat";
export default {
  data() {
    return {
      infoForm: {
        from: "1924086063@qq.com",
        get: "",
        content: "",
        title:"",
        editorOption: {}
      },
     
      value: "",
      //表单验证
      rules: {
        a_title: [{ required: true, message: "请输入标题", trigger: "blur" }],
        a_content: [
          { required: true, message: "请输入详细内容", trigger: "blur" }
        ]
      }
    };
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill;
    }
  },
  mounted() {
    //初始化
  },
  methods: {
    onEditorReady(editor) {},
    onSubmit() {
      //提交
      //this.$refs.infoForm.validate，这是表单验证
      var params = {
        from: this.infoForm.from,
        content: this.infoForm.content,
        get:this.infoForm.get,
        title: this.infoForm.title,
      };
      this.$refs.infoForm.validate(valid => {
        if (valid) {
          sendMial("/mail/sendMail", params).then(res => {
            if (res.code === 200) {
              location.reload();
              this.$message(res.data);
            } else if (res.code === 500) {
              this.$message(res.data);
            }
          });
        }
      });
    }
  },
  components: {
    //使用编辑器
    quillEditor
  }
};
</script>
<style scoped>
.main {
  width: 80%;
  height: 650px;
  margin-top: 10px;
  border: 2px solid;
  margin-left: 150px;
}
</style>
